home *** CD-ROM | disk | FTP | other *** search
/ An Introduction to Progr…l Basic 6.0 (4th Edition) / An Introduction to Programming using Visual Basic 6.0.iso / COMMON / TOOLS / VB / UNSUPPRT / DANIM / SAMPLES / DA / VISUALBASIC / SHOWCASE / COFFEE / COFFEE.FRM (.txt) next >
Encoding:
Visual Basic Form  |  1998-03-12  |  6.6 KB  |  154 lines

  1. VERSION 5.00
  2. Object = "{34F681D0-3640-11CF-9294-00AA00B8A733}#1.0#0"; "danim.dll"
  3. Begin VB.Form coffee 
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "Coffee"
  6.    ClientHeight    =   4080
  7.    ClientLeft      =   45
  8.    ClientTop       =   330
  9.    ClientWidth     =   7800
  10.    LinkTopic       =   "Form1"
  11.    MaxButton       =   0   'False
  12.    MinButton       =   0   'False
  13.    ScaleHeight     =   4080
  14.    ScaleWidth      =   7800
  15.    StartUpPosition =   3  'Windows Default
  16.    Begin DirectAnimationCtl.DAViewerControlWindowed DAViewerControlWindowed 
  17.       Height          =   3850
  18.       Left            =   120
  19.       OleObjectBlob   =   "coffee.frx":0000
  20.       TabIndex        =   0
  21.       Top             =   120
  22.       Width           =   7575
  23.    End
  24. Attribute VB_Name = "coffee"
  25. Attribute VB_GlobalNameSpace = False
  26. Attribute VB_Creatable = False
  27. Attribute VB_PredeclaredId = True
  28. Attribute VB_Exposed = False
  29. ' Visual Basic verion of Coffee
  30. Dim mediaBase, geoBase, imgBase, midiBase As String
  31. Private Sub Form_Load()
  32.   mediaBase = CurDir + "\..\..\..\..\..\Media\"
  33.   geoBase = mediaBase + "geometry\"
  34.   imgBase = mediaBase + "image\"
  35.   sndBase = mediaBase + "sound\"
  36.   'Set the background
  37.   Set imgBackGround = ImportImage(imgBase + "clouds_coffee.gif")
  38.   'Create the final montage by layering the espresso machine, the cups and the steam
  39.   'on top of each other.
  40.   Set finalMtg = UnionMontage(UnionMontage(steamMontage(), _
  41.     montage()), machineMontage())
  42.   'Create the final image.
  43.   Set finalImage = Overlay(finalMtg.Render(), Overlay(beans(), imgBackGround))
  44.   Set finalImage = Overlay(finalImage, SolidColorImage(White))
  45.   DAViewerControlWindowed.UpdateInterval = 0.2
  46.   'Display the final image.
  47.   DAViewerControlWindowed.Image = finalImage
  48.   'Set the sound.
  49.   DAViewerControlWindowed.sound = Mix(sound().Pan(-1), sound().Pan(1))
  50.   'Start the animation.
  51.   DAViewerControlWindowed.Start
  52. End Sub
  53. Function sound()
  54.   'This function creates the sound, which starts out as silence, and then
  55.   'changes to steam.mp2 when the image is clicked.
  56.   Set steamDurationConst = DANumber(7.25)
  57.   Set steamSound = ImportSound(sndBase + "steam.mp2").sound
  58.   Set s0 = CreateObject("DirectAnimation.DASound")
  59.     s0.Init DAStatics.Until(Silence, LeftButtonDown, _
  60.       DAStatics.Until(steamSound.Gain(0.85), TimerAnim(steamDurationConst), s0))
  61.   Set sound = s0
  62. End Function
  63. Function montage()
  64.   'This function creates a montage of five cups, which rotate around the espresso
  65.   'machine.  The orbit is constructed by the orbitCup function.
  66.   pi = 3.14159265359
  67.   total = 5
  68.   Set cupImageX = EmptyMontage
  69.   For i = 0 To total
  70.     Set cupImageX = UnionMontage(cupImageX, orbitCup(Add(Mul(DANumber(i), _
  71.       Mul(DANumber(2), Div(DANumber(pi), DANumber(total)))), LocalTime)))
  72.   Next
  73.   Set montage = cupImageX
  74. End Function
  75. Function beans()
  76.   'This function creates the beans you see in the background.  Two images,
  77.   'bean1.gif and bean2.gif are imported, and then moved across the screen
  78.   'while being rotated.
  79.   Set delay = DANumber(0.5)
  80.   Set Size = DANumber(0.5)
  81.   Set initBean1 = ImportImage(imgBase + "bean1.gif")
  82.   Set initBean2 = ImportImage(imgBase + "bean2.gif")
  83.   Set image0 = CreateObject("DirectAnimation.DAImage")
  84.   Set image1 = CreateObject("DirectAnimation.DAImage")
  85.   image0.Init DAStatics.Until(initBean1, TimerAnim(delay), image1)
  86.   image1.Init DAStatics.Until(initBean2, TimerAnim(delay), image0)
  87.   Set bean1 = image0.Transform(Scale2UniformAnim(Size))
  88.   Set bean2 = image1.Transform(Scale2UniformAnim(Size))
  89.   Set beans = Overlay(bean1.Transform(Translate2(-0.01, -0.01)), _
  90.     bean2.Transform(Translate2(0.01, 0)))
  91.   Set rain = beans.Tile()
  92.   Set motion = Mul(LocalTime, Mul(DANumber(2), _
  93.     Div(DANumber(0.03), DANumber(4))))
  94.   Set beans = rain.Transform(Translate2Anim(Neg(motion), Neg(motion)))
  95. End Function
  96. Function machineMontage()
  97.   'This function displays the espresso machine.
  98.   Set steamDurationConst = DANumber(7.25)
  99.   Set espreso1 = ImportImage(imgBase + "espreso1.gif")
  100.   Set espreso2 = ImportImage(imgBase + "espreso2.gif")
  101.   Set image5 = CreateObject("DirectAnimation.DAImage")
  102.     image5.Init DAStatics.Until(espreso1, LeftButtonDown, _
  103.       DAStatics.Until(espreso2, TimerAnim(steamDurationConst), image5))
  104.   Set machineMontage = ImageMontage(image5, 0)
  105. End Function
  106. Function steamMontage()
  107.   'This function displays the steam you see when you click on the image.
  108.   Set steamDurationConst = DANumber(7.25)
  109.   Dim steamImages(4)
  110.   Set steamImages(0) = ImportImage(imgBase + "steam_1.gif")
  111.   Set steamImages(1) = ImportImage(imgBase + "steam_2.gif")
  112.   Set steamImages(2) = ImportImage(imgBase + "steam_3.gif")
  113.   Set steamImages(3) = ImportImage(imgBase + "steam_4.gif")
  114.   Set steamImages(4) = ImportImage(imgBase + "steam_5.gif")
  115.   Set steamLen = DANumber(4)
  116.   Set condition = GT(Add(Div(Mul(LocalTime, steamLen), _
  117.     steamDurationConst), DANumber(1)), steamLen)
  118.   Set result2 = Add(Div(Mul(LocalTime, steamLen), _
  119.     steamDurationConst), DANumber(1))
  120.   Set Index = Cond(condition, steamLen, result2)
  121.   Set a = DAStatics.Array(steamImages)
  122.   Set s0 = CreateObject("DirectAnimation.DAImage")
  123.     s0.Init DAStatics.Until(EmptyImage, LeftButtonDown, _
  124.       DAStatics.Until(a.NthAnim(Index), TimerAnim(steamDurationConst), s0))
  125.   Set image1 = s0.Transform(Translate2(-0.0085, 0.002))
  126.   Set steamMontage = ImageMontage(image1, -0.0001)
  127.   End Function
  128. Function orbitCup(angle)
  129.   pi = 3.14159265359
  130.   Set pos = Point3(0, 0.05, 0)
  131.   Set pos = pos.Transform(Compose3(Rotate3Anim(XVector3, Mul(DANumber(7), _
  132.     Div(DANumber(pi), DANumber(16)))), Rotate3Anim(ZVector3, angle)))
  133.   Set cupAngle = LocalTime
  134.   Set imageXX = cupImage(cupAngle).Transform(Compose2(Translate2Anim(pos.X, pos.Y), _
  135.     Scale2UniformAnim(DAStatics.Sub(DANumber(1), _
  136.       Mul(DAStatics.Abs(DAStatics.Cos(Div(angle, _
  137.         DANumber(2)))), DANumber(0.5))))))
  138.   Set orbitCup = ImageMontageAnim(imageXX, Neg(pos.Z))
  139. End Function
  140. Function cupImage(cupAngle)
  141.   pi = 3.14159265359
  142.   Dim cupImages
  143.   cupImages = Array(ImportImage(imgBase + "cup1.gif"), _
  144.     ImportImage(imgBase + "cup2.gif"), ImportImage(imgBase + "cup3.gif"), _
  145.       ImportImage(imgBase + "cup4.gif"), ImportImage(imgBase + "cup5.gif"), _
  146.         ImportImage(imgBase + "cup6.gif"), ImportImage(imgBase + "cup7.gif"), _
  147.           ImportImage(imgBase + "cup8.gif"))
  148.   Set Number = DANumber(7)
  149.   Set Index = Add(DAStatics.Mod(Mul(Number, Div(cupAngle, _
  150.     Mul(DANumber(2), DANumber(pi)))), Number), DANumber(1))
  151.   Set a = DAStatics.Array(cupImages)
  152.   Set cupImage = a.NthAnim(Index)
  153. End Function
  154.